'use strict'

exports.register = function( server , option , next){

	//静态文件接口
    server.route({
        method: 'GET',
        path: '/{filename*}',
        config: {
            auth: false,
            cache: {
                expiresIn: 24 * 60 * 60 * 1000,
                privacy: 'public'
            }
        },
        handler: {
            directory: {
                path: __dirname + '/public',
                listing: false,
                index: false
            }
        }
    });

    /*
     *  公共接口
     *  莫凡微信公众号获取签名
     *  @return {json} {errCode:0,msg:'ok',data:{timestamp:'',nonceStr:'',signature:''}}
     *
     */
    server.route({
        method: ['GET','POST'],
        path: '/interface/wechat/signature/get',
        handler: function(request,reply){
            var reobj = {
                'errCode':0,
                'msg':'ok',
                'data':{}
            }
            reobj.data.timestamp = '123';
            reobj.data.nonceStr = '123';
            reobj.data.signature = '123';
            return reply(JSON.stringify(reobj));
            // var options = request.payload||request.url.query;
            // if(typeof options.url!='undefined'){
            //     wxApi.sign(decodeURIComponent(options.url)).then((signature)=>{
            //         reobj.data = signature;
            //         return reply(JSON.stringify(reobj));
            //     });
            // }else{
            //     reobj.errCode = '40005';
            //     reobj.msg = 'Invaild user!';
            //     return reply(JSON.stringify(reobj));
            // }
        }
    });

	return next();
}

exports.register.attributes = {
	name: 'route-main'
}